package qc.module.iot.protocol.ddp;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * DDP_V30 DTU端发送的包类型
 *
 * @author QuCheng Tech
 * @since 2025/11/9
 */
@Getter
@AllArgsConstructor
public enum DDP_V30_DtuSendPacketsTypeEnum {
    UN_DEFINE(0, "未定义"),
    LOGON_IN(0x01, "终端请求注册"),
    LOGON_OUT(0x02, "终端请求注销"),
    INVALID(0x04, "无效命令或协议包"),//一般在查询或设置指令时使用
    REPLY_RECEIVE_USER_DATA(0x05, "接收到dsc用户数据的应答包"),
    SEND_USER_DATA(0x09, "发送给dsc的用户数据包"),
    REPLY_QUERY_PARAM(0x0B, "查询DTU参数的应答包"),
    REPLY_SET_PARAM(0x0D, "设置DTU参数的应答包"),
    REPLY_QUERY_LOG(0x0E, "提取DTU日志的应答包"),
    REPLY_UPGRADE(0x0F, "远程升级的回应包");

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节
     * @return qc.module.iot.protocol.ddp.DDP_V30_DtuSendPacketsTypeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static DDP_V30_DtuSendPacketsTypeEnum getDDP_V30_DtuSendPacketsTypeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0xFF;//传入的值限制为1字节，最大0xFF
            if (byteIntValue > 0x0) {
                for (DDP_V30_DtuSendPacketsTypeEnum item : DDP_V30_DtuSendPacketsTypeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return DDP_V30_DtuSendPacketsTypeEnum.UN_DEFINE;
    }
}
